package com.atguigu.flink.chapter10;

import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.DataTypes;
import org.apache.flink.table.api.Schema;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

/**
 * @Author lzc
 * @Date 2023/6/27 09:23
 */
public class TableApiDemo4 {
    public static void main(String[] args) throws Exception {
        // 1. 表的执行
        /*EnvironmentSettings conf = EnvironmentSettings.newInstance()
            .inStreamingMode()
            .build();
        TableEnvironment tEnv = TableEnvironment.create(conf);*/
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        DataStreamSource<Tuple2<String, Long>> stream = env.fromElements(
            Tuple2.of("a", 1L),
            Tuple2.of("b", 2L)
        );
    
        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
    
//        Table table = tEnv.fromDataStream(stream, $("word"), $("count"));
        Schema scheme = Schema.newBuilder()
            .column("f0", DataTypes.STRING())
            .column("f1", DataTypes.BIGINT())
            .build();
        Table table = tEnv.fromDataStream(stream, scheme);
        table.printSchema();
    
    
    }
}
